package AST;

import java.util.ArrayList;
import java.util.List;

public class ClassDef extends CompoundStmt {
	private SPyName name;
	private Atom atom;
	private List<Atom> atomList = new ArrayList<Atom>();
	private Suite suite;

	public ClassDef(SPyName name, Atom atom, List<Atom> atomList, Suite suite) {
		print();
		this.name = name;
		this.atom = atom;
		this.atomList = atomList;
		this.suite = suite;
	}

	public ClassDef() {
		print();
	}

	public SPyName getName() {
		return name;
	}

	public void setName(SPyName name) {
		this.name = name;
	}

	public Atom getAtom() {
		return atom;
	}

	public void setAtom(Atom atom) {
		this.atom = atom;
	}

	public List<Atom> getAtomList() {
		return atomList;
	}

	public void setAtomList(List<Atom> atomList) {
		this.atomList = atomList;
	}

	public Suite getSuite() {
		return suite;
	}

	public void setSuite(Suite suite) {
		this.suite = suite;
	}

	public void print() {
		System.out.println("ClassDef");
	}

	public void addAtomList(Atom atom2) {
		this.atomList.add(atom2);

	}

	public void genC(PW pw) {
		String str_name = this.getName().getName().toString();
		// classdef: 'class' NAME ['(' [atom [',' atom]* ] ')'] ':' suite

		pw.print("typedef\n");
		pw.print("\tstruct _St_" + str_name + " {\n");
		pw.print("\t\tFunc *vt;\n");
		pw.print("\t} _class_" + str_name + ";");
		pw.print("\n\n");

		pw.print("_class_" + str_name + " *new_" + str_name + "(void);\n");
		// falta tratar quando tem atom

		this.suite.genC(pw);

		pw.print("_class_" + str_name + " *new_" + str_name + "()\n");
		pw.print("{\n");
		pw.print("\t_class_" + str_name + " *t;\n\n");
		pw.print("\tif ((t = malloc(sizeof(_class_" + str_name
				+ "))) != NULL )\n");
		pw.print("\t\tt->vt = VTclass_" + str_name + ";\n");
		pw.print("\treturn t;\n");
		pw.print("}");

	}

}
